package com.dkd.common.config;

import org.dromara.autotable.core.constants.DatabaseDialect;
import org.dromara.autotable.core.interceptor.BuildTableMetadataInterceptor;
import org.dromara.autotable.core.strategy.TableMetadata;
import org.dromara.autotable.core.strategy.mysql.data.MysqlTableMetadata;
import org.springframework.stereotype.Component;

@Component
public class MyBuildTableMetadataInterceptor implements BuildTableMetadataInterceptor {

    //拦截修改表信息 BuildTableMetadataInterceptor
    //表注解拦截器 AutoTableAnnotationInterceptor
    //建表前拦截器 BuildTableMetadataInterceptor
    //修改表前拦截器 ModifyTableInterceptor
    @Override
    public void intercept(String databaseDialect, TableMetadata tableMetadata) {
        if (DatabaseDialect.MySQL.equals(databaseDialect)) {
            MysqlTableMetadata mysqlTableMetadata = (MysqlTableMetadata) tableMetadata;
            mysqlTableMetadata.setComment(mysqlTableMetadata.getComment() + "-表注释");
        }
        //事件回调
        //AutoTable准备好了，即将开始执行的回调 AutoTableReadyCallback
        //建表回调 CreateTableFinishCallback
        //修改表后回调 ModifyTableFinishCallback
        //单个表执行前回调 RunBeforeCallback
        //单个表执行后回调 RunAfterCallback
        //验证模式：验证完回调 ValidateFinishCallback
        //执行结束回调 AutoTableFinishCallback
    }
}
